<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Rest_Server - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.rest.server.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.rest.server.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.rest.client.html">Zend_Rest_Client</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.rest.html">Zend_Rest</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.search.lucene.html">Zend_Search_Lucene</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.rest.server" class="section"><div class="info"><h1 class="title">Zend_Rest_Server</h1></div>
    

    <div class="section" id="zend.rest.server.introduction"><div class="info"><h1 class="title">Introduction</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Rest_Server</span> is intended as a fully-featured REST server.
        </p>
    </div>

    <div class="section" id="zend.rest.server.usage"><div class="info"><h1 class="title">REST Server Usage</h1></div>
        

        <div class="example" id="zend.rest.server.usage.example-1"><div class="info"><p><b>Example #1 Basic Zend_Rest_Server Usage - Classes</b></p></div>
            

            <pre class="programlisting brush: php">
$server = new Zend_Rest_Server();
$server-&gt;setClass(&#039;My_Service_Class&#039;);
$server-&gt;handle();
</pre>

        </div>

        <div class="example" id="zend.rest.server.usage.example-2"><div class="info"><p><b>Example #2 Basic Zend_Rest_Server Usage - Functions</b></p></div>
            

            <pre class="programlisting brush: php">
/**
 * Say Hello
 *
 * @param string $who
 * @param string $when
 * @return string
 */
function sayHello($who, $when)
{
    return &quot;Hello $who, Good $when&quot;;
}

$server = new Zend_Rest_Server();
$server-&gt;addFunction(&#039;sayHello&#039;);
$server-&gt;handle();
</pre>

        </div>
    </div>

    <div class="section" id="zend.rest.server.args"><div class="info"><h1 class="title">Calling a Zend_Rest_Server Service</h1></div>
        

        <p class="para">
            To call a <span class="classname">Zend_Rest_Server</span> service, you must supply a
            <b><tt>GET</tt></b>/POST <code class="code">method</code> argument with a value that is the
            method you wish to call. You can then follow that up with any number
            of arguments using either the name of the argument (i.e. &quot;who&quot;) or
            using <code class="code">arg</code> following by the numeric position of the
            argument (i.e. &quot;arg1&quot;).
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Numeric index</b><br /></span>
            

            <p class="para">
                Numeric arguments use a 1-based index.
            </p>
        </p></blockquote>

        <p class="para">
            To call <code class="code">sayHello</code> from the example above, you can use either:
        </p>

        <p class="para">
            <code class="code">?method=sayHello&amp;who=Davey&amp;when=Day</code>
        </p>

        <p class="para">
            or:
        </p>

        <p class="para">
            <code class="code">?method=sayHello&amp;arg1=Davey&amp;arg2=Day</code>
        </p>
    </div>

    <div class="section" id="zend.rest.server.customstatus"><div class="info"><h1 class="title">Sending A Custom Status</h1></div>
        

        <p class="para">
            When returning values, to return a custom status, you may return an
            array with a <code class="code">status</code> key.
        </p>

        <div class="example" id="zend.rest.server.customstatus.example-1"><div class="info"><p><b>Example #3 Returning Custom Status</b></p></div>
            

            <pre class="programlisting brush: php">
/**
 * Say Hello
 *
 * @param string $who
 * @param string $when
 * @return array
 */
function sayHello($who, $when)
{
    return array(&#039;msg&#039; =&gt; &quot;An Error Occurred&quot;, &#039;status&#039; =&gt; false);
}

$server = new Zend_Rest_Server();
$server-&gt;addFunction(&#039;sayHello&#039;);
$server-&gt;handle();
</pre>

        </div>
    </div>

    <div class="section" id="zend.rest.server.customxml"><div class="info"><h1 class="title">Returning Custom XML Responses</h1></div>
        

        <p class="para">
            If you wish to return custom <acronym class="acronym">XML</acronym>, simply return a
            <code class="code">DOMDocument</code>, <code class="code">DOMElement</code> or
            <code class="code">SimpleXMLElement</code> object.
        </p>

        <div class="example" id="zend.rest.server.customxml.example-1"><div class="info"><p><b>Example #4 Return Custom XML</b></p></div>
            

            <pre class="programlisting brush: php">
/**
 * Say Hello
 *
 * @param string $who
 * @param string $when
 * @return SimpleXMLElement
 */
function sayHello($who, $when)
{
    $xml =&#039;&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;mysite&gt;
    &lt;value&gt;Hey $who! Hope you\&#039;re having a good $when&lt;/value&gt;
    &lt;code&gt;200&lt;/code&gt;
&lt;/mysite&gt;&#039;;

    $xml = simplexml_load_string($xml);
    return $xml;
}

$server = new Zend_Rest_Server();
$server-&gt;addFunction(&#039;sayHello&#039;);

$server-&gt;handle();
</pre>

        </div>

        <p class="para">
            The response from the service will be returned without modification
            to the client.
        </p>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.rest.client.html">Zend_Rest_Client</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.rest.html">Zend_Rest</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.search.lucene.html">Zend_Search_Lucene</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.rest.html">Zend_Rest</a></li>
  <li><a href="zend.rest.introduction.html">Introduction</a></li>
  <li><a href="zend.rest.client.html">Zend_Rest_Client</a></li>
  <li class="active"><a href="zend.rest.server.html">Zend_Rest_Server</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>